#coding=UTF-8
from IR.moduels.AutoFill import  AutoFill
import random
import sys
from django.shortcuts import HttpResponse
import json
from IR.Util.Variables import Constant


def auto_fill(request):
    if (request.method == "POST"):
        query_text = request.POST.get(Constant.QUERY_TEXT, None)

        page_num = int(request.POST.get(Constant.PAGE_NUM, 1))
        count = int(request.POST.get(Constant.COUNT, 20))

        result = dict()
        if(query_text==None or query_text==""):
            result[Constant.ERROR_CODE] = 1
            result[Constant.ERROR_MESSAGE] = "query text is null"
            result[Constant.STATUS] = Constant.FAIL
            return HttpResponse(json.dumps(result), content_type="application/json")
        else:
            auto_fill = AutoFill()
            item = auto_fill.complete_query('国务院') #调用实例，对“国务院”查询做自动补齐，以列表方式返回top5的补齐推荐
            result["data"]=item
            result[Constant.STATUS] = Constant.SUCCESS
            return HttpResponse(json.dumps(result), content_type="application/json")

